<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>DNS、iredmaill 邮件服务 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>DNS、iredmaill 邮件服务</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="DNS"><a href="#DNS" class="headerlink" title="DNS"></a>DNS</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;全称domain name server。域名服务器，用来解析域名的。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%E3%80%81iredmaill%E9%82%AE%E4%BB%B6%E6%9C%8D%E5%8A%A1/01.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;域名标准写法：www.qq.com.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS是如何实现解析域名的：客户端先查找/etc/hosts里是否有对应域名的ip，没有的话查找dns服务器（在/etc/resolv.conf下配置的），首先查找缓存，缓存没有，找.根名称服务器DNS，根名称服务器说没有，但我知道.com，又找.com顶级名称服务器，从.com找到microsoft.com。最终找到example.microsoft.com。找的过程都是找的dns服务器。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># yum install -y bind</span></div><div class="line">[root@linux ~]<span class="comment"># vi /etc/named.conf          //以下是用到的配置信息，其它暂且不理会</span></div><div class="line">options &#123;</div><div class="line">        listen-on port 53 &#123; 127.0.0.1; &#125;;                //监听端口53，监听53端口的ip是谁</div><div class="line">        listen-on-v6 port 53 &#123; ::1; &#125;;                     //ipv6</div><div class="line">        directory       <span class="string">"/var/named"</span>;                    //子配置文件所对应的目录</div><div class="line">logging &#123;</div><div class="line">        channel default_debug &#123;</div><div class="line">                file <span class="string">"data/named.run"</span>;                    //日志。路径/var/named/data/named.run</div><div class="line">                severity dynamic;</div><div class="line">        &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"."</span> IN &#123;                                                    //.就是根域</div><div class="line">        <span class="built_in">type</span> hint;                                                //<span class="built_in">type</span>有三种，master主，slave从，hint根域的hint</div><div class="line">        file <span class="string">"named.ca"</span>;                                      //根域对应的文件。文件在/var/named/下</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/named.ca        //每一个域对应一个机器。</span></div><div class="line">[root@linux ~]<span class="comment"># cat /var/named/named.localhost</span></div><div class="line"><span class="variable">$TTL</span> 1D                                                                          //1D就是1天生存周期</div><div class="line">@       IN SOA  @ rname.invalid. (                                 //SOA指的是解析记录。如A、CNAME等</div><div class="line">                                        0       ; serial                 //序列号</div><div class="line">                                        1D      ; refresh            //从每隔一段时间刷一次和主的数据是否有更新</div><div class="line">                                        1H      ; retry               //发现和主不通了，再过多长时间去试一下。</div><div class="line">                                        1W      ; expire            //过期时间。缓存时间，一周</div><div class="line">                                        3H )    ; minimum       //和上面的TTL有关，上面没有定义，以此项为准 </div><div class="line">          NS          @</div><div class="line">          A             127.0.0.1</div><div class="line">          AAAA      ::1                                   //ipv6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其中第二行的@符号指的是/etc/named.rfc1912.zones中定义的zone引号里面的内容。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named start</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 localhost</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 localhost.localdomain</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 -x 127.0.0.1     //测试反解析          //反解析</span></div></pre></td></tr></table></figure>
<h3 id="1-正向解析"><a href="#1-正向解析" class="headerlink" title="1.正向解析"></a>1.正向解析</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf                  //在内容的最后面增加以下内容</span></div><div class="line">zone <span class="string">"123.com"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> master;</div><div class="line">        file <span class="string">"123.com.zone"</span>;</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># named-checkconf                      //检测是否有错</span></div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/123.com.zone</span></div><div class="line"><span class="variable">$TTL</span> 1D</div><div class="line">@        IN SOA  @ admin.123.com. (</div><div class="line">                                        20161025       ; serial</div><div class="line">                                        1D      ; refresh</div><div class="line">                                        1H      ; retry</div><div class="line">                                        1W      ; expire</div><div class="line">                                        3H )    ; minimum</div><div class="line">           IN  NS      ns.123.com.</div><div class="line">           IN  MX  5   mail.123.com.</div><div class="line">mail    IN  A       192.168.1.20</div><div class="line">ns       IN  A       192.168.1.70                       //对外服务应写公网ip</div><div class="line">www   IN  A       11.11.11.11</div><div class="line">bbs     IN  CNAME   www</div><div class="line">[root@linux ~]<span class="comment"># named-checkzone "123.com" /var/named/123.com.zone</span></div><div class="line">zone 123.com/IN: loaded serial 20161025</div><div class="line">OK</div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf</span></div><div class="line">options &#123;</div><div class="line">        listen-on port 53 &#123; 127.0.0.1;192.168.1.70; &#125;;</div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.70 www.123.com</span></div></pre></td></tr></table></figure>
<h3 id="2-反向解析"><a href="#2-反向解析" class="headerlink" title="2.反向解析"></a>2.反向解析</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;想做邮件服务器，最好加下反解析。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf          //添加以下内容</span></div><div class="line">zone <span class="string">"1.168.192.in-addr.arpa"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> master;</div><div class="line">        file <span class="string">"1.168.192.zone"</span>;</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/1.168.192.zone</span></div><div class="line"><span class="variable">$TTL</span> 1D</div><div class="line">@        IN SOA  @ admin.123.com. (</div><div class="line">                                        20161025       ; serial</div><div class="line">                                        1D      ; refresh</div><div class="line">                                        1H      ; retry</div><div class="line">                                        1W      ; expire</div><div class="line">                                        3H )    ; minimum</div><div class="line">           IN  NS      ns.123.com.</div><div class="line">160     IN  PTR     ns.123.com.</div><div class="line">20       IN  PTR     mail.123.com.</div><div class="line">[root@linux ~]<span class="comment"># named-checkconf</span></div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.70 -x 192.168.1.20</span></div></pre></td></tr></table></figure>
<h3 id="从DNS服务器"><a href="#从DNS服务器" class="headerlink" title="从DNS服务器"></a>从DNS服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># yum install -y bind             </span></div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf               //注释//这两行将会监听服务器上所有端口</span></div><div class="line">options &#123;</div><div class="line">//        listen-on port 53 &#123; 127.0.0.1;192.168.1.70; &#125;;</div><div class="line">//        listen-on-v6 port 53 &#123; ::1; &#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf              //在文件下面添加以下信息</span></div><div class="line">zone <span class="string">"123.com"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> slave;</div><div class="line">        file <span class="string">"slaves/123.com.zone"</span>;</div><div class="line">     masters &#123; 192.168.11.160; &#125;;                      //注意大括号前后面有空格。</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named start</span></div><div class="line">[root@linux ~]<span class="comment"># ls /var/named/slave     //有没有生成这两个文件 </span></div><div class="line">11.168.192.zone   123.com.zone</div><div class="line">[root@linux ~]<span class="comment"># cat /var/named/slaves/123.com.zone         //查看和主上是否一致</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.20 www.123.com               //检测解析</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.20 -x 192.168.1.70</span></div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/123.com.zone   //增加一个域名记录</span></div><div class="line">aming    IN    A          111.111.111.111</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主上有更改，从上立马生效，需要在主配置文件中添加两条notify yes;also-notify { 192.168.1.20; };</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># named-checkconf</span></div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div></pre></td></tr></table></figure>
<h2 id="iredmaill"><a href="#iredmaill" class="headerlink" title="iredmaill"></a>iredmaill</h2><h3 id="iredmail安装"><a href="#iredmail安装" class="headerlink" title="iredmail安装"></a>iredmail安装</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;iRedMail 是一个基于 Linux/BSD 系统的零成本、功能完备、成熟的邮件服务器解决方案。<a href="www.iredmail.com">官网</a></p>
<h4 id="iRedmail包含的套件："><a href="#iRedmail包含的套件：" class="headerlink" title="iRedmail包含的套件："></a>iRedmail包含的套件：</h4><ul>
<li>postfix发邮件的</li>
<li>dovecot收邮件的</li>
<li>apache网页web访问，数据存放mysql或者openldap里面。</li>
<li>policyd拒绝黑名单</li>
<li>amavisd杀毒、扫描垃圾邮件</li>
<li>roundcube在web页面访问邮箱收发邮件的套件。即webmail</li>
<li>awstat分析日志</li>
<li>fail2ban防止暴力破解</li>
<li>iRedAdmin管理邮件，账户增加、删除、修改</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需有域名和服务器，服务器配置内存不低于1G</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先修改域名的MX记录指向自定义的比如mail.lishiming.net上 ,mail.lishiming.net需A记录指向购买的公网服务器ip上。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># hostname mail.lishiming.net</span></div><div class="line">[root@linux ~]<span class="comment"># vim /etc/hosts</span></div><div class="line">127.0.0.1   mail.lishiming.net   localhost</div><div class="line">[root@linux ~]<span class="comment"># wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.5-1.tar.bz2</span></div><div class="line">[root@linux ~]<span class="comment"># cd iRedMail-0.9.0</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># cd pkgs/</span></div><div class="line">[root@linux pkgs]<span class="comment"># vim get_all.sh           //里面的iredmail.org修改一下</span></div><div class="line">[root@linux pkgs]<span class="comment"># sed -i 's/iredmail.org/106.187.51.47/g' get_all.sh     //ip是日本的代理服务器</span></div><div class="line">[root@linux pkgs]<span class="comment"># cd ..</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># sh iRedMail.sh</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将会出来类似于图片界面，yes–Next–按tab选择Apache（按空格键选项前会出来*号说明选中）–选择MySQL–设置mysql密码–设置域（填写域名）–设置管理员的密码–Next。输入y–是否启用iptables选择n–移动my.cnf选择y。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># for s in httpd iredapd amavisd clamd postfix dovecot cbpolicyd spamassassin clamd.amavisd saslauthd fail2ban; do /etc/init.d/$s restart; done</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动以上这些服务。</p>
<h3 id="iredmail使用"><a href="#iredmail使用" class="headerlink" title="iredmail使用"></a>iredmail使用</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;唯有dovecot启动是失败，错误提示ipv6的ip失败，这时需编辑配置文件。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># vim /etc/dovecot/dovecot.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">listen = *  [::]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">listen = *</div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># /etc/init.d/dovecot restart</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这时浏览器访问：<a href="https://mail.lishiming.net/iredadmin" target="_blank" rel="external">https://mail.lishiming.net/iredadmin</a>        //提示：您的连接不是私密连接，这时点击下面的“高级”–继续访问。Add–User  增加一个邮箱用户。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;foxmail新建一个账号，输入新建的邮箱用户名和密码。</p>
<p><figure class="figure"><img src="http://note.youdao.com/yws/public/resource/f413494d6e99fd7f2fc23e25ee770484/xmlnote/73083A746F144E6E865BCFAB35CBF944/7728" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;接下来，进行发收邮件的测试。这时收件时速度有些慢，更改以下文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># vim /etc/policyd/cluebringer.conf           </span></div><div class="line">注释<span class="comment">#Greylisting               //灰名单</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># /etc/init.d/postfix restart; /etc/init.d/dovecot restart;/etc/init.d/cbpolicyd restart</span></div></pre></td></tr></table></figure>
<h3 id="iredmail增加域"><a href="#iredmail增加域" class="headerlink" title="iredmail增加域"></a>iredmail增加域</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;5d6d.com   MX   mail.lishiming.net.             //解析</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器访问：<a href="https://mail.lishiming.net/iredadmin" target="_blank" rel="external">https://mail.lishiming.net/iredadmin</a>        //Add–Domain  增加一个域。5d6d.com</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;之后Add增加一个邮箱用户名lishiming@5d6d.com</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在foxmail上右上角–账号管理–增加账号</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试收发邮件。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Dns、Iredmaill/1. dns、iredmail邮件服务/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
